﻿<?php
require_once(dirname(__FILE__) .'/include/Database.php');

class QuizModel{
	public function getCate(){
		$model = Database::getInstance();
		$model->setQuery('select id, name, active from bcb_quiz_cate');
		return $model->getArray();
	}

	public function getCateById($cateId){
		$model = Database::getInstance();
		$model->setQuery('select id, name, number_quiz, active from bcb_quiz_cate where id='.$cateId);
		return $model->getRow();
	}

	public function addCate($aryData){
		$model = Database::getInstance();
		return $model->insert('bcb_quiz_cate',$aryData);
	}

	public function editCate($cateId,$aryData){
		$model = Database::getInstance();
		return $model->update('bcb_quiz_cate',$cateId, $aryData);
	}
	
	public function delCate($cateId){
		$model = Database::getInstance();
		return $model->delete('bcb_quiz_cate',$cateId);
	}

	public function getQuiz($cateId, $off, $len){
		$model = Database::getInstance();
		$sql = 'select id, content, choices, answer, cate_id, active from bcb_quiz where cate_id = '.$cateId;
		if ($len>0) {
			$sql .= " limit $off, $len";
		}
		$model->setQuery($sql);
		return $model->getArray();
	}

	public function getQuizById($quizId){
		$model = Database::getInstance();
		$model->setQuery('select id, content, choices, answer, cate_id, active from bcb_quiz where id = '.$quizId);
		return $model->getRow();
	}

	public function editQuiz($quizId,$aryData){
		$model = Database::getInstance();
		return $model->update('bcb_quiz',$quizId, $aryData);
	}
}
?>